//
//  ViewController.m
//  testAVFoundation
//
//  Created by Ran on 15/11/3.
//  Copyright (c) 2015年 gintong. All rights reserved.
//

#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
#import "RanPhotoPickerViewController.h"

@interface ViewController ()<UIImagePickerControllerDelegate>

/*
@property(nonatomic, strong)AVPlayer *player;
*/
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)dealloc
{
    
}

- (void)setupUI
{
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"next" style:UIBarButtonItemStylePlain target:self action:@selector(nextBtnClicked)];
}

- (void)nextBtnClicked
{
    RanPhotoPickerViewController *vc = [RanPhotoPickerViewController new];
    vc.navigationTitle = @"我的照片";
    vc.navigationBackText = @"返回";
    vc.sourceType = RanPhotoPickerTypePhotoAndVideo;
    [vc showWithPushMethodFromViewController:self];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self nextBtnClicked];
}

/*
- (void)setupUI
{
    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
    playerLayer.backgroundColor = [UIColor grayColor].CGColor;
    playerLayer.frame = CGRectMake(0, 100, self.view.frame.size.width, 250);
    [self.view.layer addSublayer:playerLayer];
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.player play];
}

#pragma mark - Getter

- (AVPlayer *)player
{
    if(!_player){
        self.player = ({
            AVPlayer *player = [AVPlayer playerWithPlayerItem:[self getPlayerItem:0]];
            player;
        });
    }
    return _player;
}

- (AVPlayerItem *)getPlayerItem: (int)videoIndex{
    NSString *urlString = [NSString stringWithFormat:@"%d", videoIndex];
    urlString = @"http://localhost/storm.mp4";
    urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:urlString];
    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
    return playerItem;
}
*/
 
@end









